/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication6.DomainLayer;

/**
 *
 * @author meydlo
 */
import java.util.ArrayList;
public class CustomerRecords{

    private static CustomerRecords customerRecords;
    private ArrayList<Customer> customerList;

    //
    private CustomerRecords(){
        customerList = new ArrayList<Customer>();
    }

    //
    public static CustomerRecords getCustomerRecords(){
        if(customerRecords==null)
        {
            customerRecords=new CustomerRecords();
        }
        return customerRecords;
    }

    //
    public void addCustomer(Customer customer)
    {
        customerList.add(customer);
    }

    //
    public Customer customerByID(long id)
    {
        for(int i=0; i<customerList.size();i++){
            if(customerList.get(i).getId()==id)
            {
                return customerList.get(i);
            }
        }
        System.out.println("Customer wasn't found");
        return null;
    }



    //
    public void deleteCustomer(long id)
    {
        if(customerByID(id)!=null){
            customerList.remove(customerByID(id));
        }
    }



    //
    public ArrayList<Customer> getCustomerList()
    {
        return customerList;
    }

    public void setCustomerList(ArrayList<Customer> list)
    {
        this.customerList = list;
    }



    public void printCustomerList()
    {
        if(customerList.isEmpty()){
            System.out.println("No customer in list");
        }
        else{
            for(Customer customer : customerList){
                System.out.println("id: "+customer.getId()+"   |  name: "+customer.getName());
            }
        }
    }

    //set Discount to all business or private customers
    public void setDiscount(boolean isBusiness,double discount)
    {
        if(isBusiness==true){
            for(Customer customer : customerList){
                if(customer.getISbusinnes()==true){
                    customer.setDiscount(discount);
                }
            }
        }
        else if(isBusiness==false){
            for(Customer customer : customerList){
                if(customer.getISbusinnes()==false){
                    customer.setDiscount(discount);
                }
            }
        }
    }

    //statistics purpose
    public int getNoOfCustomers()
    {
        int noOfCustomers=customerList.size();
        return noOfCustomers;
    }
}
